/**
 * @summary 关注
 */

import req from '@/utils/request';
import * as URL from '@/constants/api';

export function follow(id) {
  return req({
    url: URL.FOLLOW,
    method: 'post',
    data: {
      target: id,
    }
  })
    .then(res => res.data.message)
    .catch(err =>{
      // console.log(Promise.reject(err))
      return Promise.reject(err.response.data.message)

    }
    );
}

/**
 * @summary 登录
 */
export function login(params) {
  return req({
    url: URL.LOGIN,
    method: 'post',
    data: params,
  })
    .then(res => {
      // 记token
      localStorage.setItem('token', `Bearer ${res.data.data.token}`);
      console.log(res)
      return res.data.message;
    })
    .catch(err => Promise.reject(err.response.data.message));
}


/**
 * @summary 用户信息
 */
export function getUserList() {
  return req({
    url: URL.USER,
    method: 'get',
  })
    .then(res => {
      return res.data.data;

    })
    .catch(err => err);
}

/**
 * @summary 用户个人资料
 */
export function getUserInfoList() {
  return req({
    url: URL.USER_INFO,
    method: 'get',
  })
    .then(res => {
      return res.data.data;
    })
    .catch(err => err);
}
